/**
 * 统一拦截错误处理中间件
 */
"use strict";
// 统一捕获egg-jwt插件错误
const { failed } = require("../utils/request");

module.exports = () => {
  return async (ctx, next) => {
    try {
      await next();
    } catch (error) {
      if (error.status === 401) {
        return (ctx.body = failed("登录校验失败"));
      }
      throw error;
    }
  };
};
